;; 编程设置

;; 使用cscope
(require 'xcscope)

;; yasnippet
(add-to-list 'load-path "~/.emacs.d/lisp/yasnippet/")
(require 'yasnippet)
(setq yas/snippet-dirs "~/.emacs.d/lisp/yasnippet/snippets")
(yas/load-directory yas/snippet-dirs)

;; auto-complete
(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/elpa/auto-complete-1.4.20110207/dict/")
(ac-config-default)
;; 关闭自动启动
(setq ac-auto-start nil)
;; 关闭自动显示补齐框
(setq ac-auto-show-menu nil)
;; 设置一些按键
(define-key ac-mode-map (kbd "TAB") 'tab-indent-or-complete)
(setq ac-use-menu-map t)
;; Default settings
(define-key ac-menu-map "\C-n" 'ac-next)
(define-key ac-menu-map "\C-p" 'ac-previous)
(define-key ac-menu-map "\C-j" 'ac-complete)
(define-key ac-menu-map "\t" 'ac-complete)

;; 设置特定模式启动auto-complete
(dolist (hook (list
	       'lua-mode-hook
	       'emacs-lisp-mode-hook
	       'lisp-mode-hook
	       'lisp-interaction-mode-hook
	       'scheme-mode-hook
	       'c-mode-hook
	       'c++-mode-hook
	       'java-mode-hook
	       'haskell-mode-hook
	       'asm-mode-hook
	       'emms-tag-editor-mode-hook
	       'sh-mode-hook
	       'python-mode-hook
	       'latex-mode-hook
	       'ruby-mode-hook
	       'graphviz-dot-mode-hook
	       ))
  ;; (add-hook hook 'auto-complete-mode)
  (add-hook hook 'yas/minor-mode))

;; 设置tab键自动选择补齐或缩进
(defun tab-indent-or-complete ()
  (interactive)
  (defun check-expansion ()
    (save-excursion
      (if (looking-at "\\_>") t
	(progn (backward-char 1)
	       (if (looking-at "\\.") t
		 (progn (backward-char 1)
			(if (looking-at "->") t nil)))))))
  (if (check-expansion)
      (auto-complete)
    (indent-for-tab-command)))

;; 使用4個空格代替縮進
(defun space-replace-tab()
  (setq tab-width 4
	c-basic-offset 4
	indent-tabs-mode nil))

;; 开启语法高亮
(global-font-lock-mode 1)

;; 使用gdb的图形模式
(setq gdb-many-windows t)

;; 配置graphviz dot mode
(load-file "~/.emacs.d/lisp/graphviz-dot-mode.el")

;; 配置ruby
(autoload 'ruby-mode "ruby-mode" "Major mode for ruby files" t)
(add-to-list 'auto-mode-alist '("\\.rb$" . ruby-mode))
(add-to-list 'interpreter-mode-alist '("ruby" . ruby-mode))

;; ido
(require 'ido)
(ido-mode t)
;; (rvm-use-default)
;; (require 'rinari)
;; ;; rhtml-mode
;; (add-to-list 'load-path "~/.emacs.d/lisp/rhtml")
;; (require 'rhtml-mode)
;; (add-hook 'rhtml-mode-hook
;;          (lambda () (rinari-launch)))
;; yaml-mode
(autoload 'yaml-mode "yaml-mode" nil t)
(add-to-list 'auto-mode-alist '("\\.yml$" . yaml-mode))
(add-hook 'yaml-mode-hook
	  '(lambda ()
	     (define-key yaml-mode-map "\C-m" 'newline-and-indent)))

(provide 'jerry-mode)
